package com.yuanfeng.job.service.impl;

import com.yuanfeng.commoms.dto.job.ExpireMarkIdUpdateDTO;
import com.yuanfeng.job.dto.ActivityNoneRecSlideDTO;
import com.yuanfeng.job.feign.OrderServiceClient;
import com.yuanfeng.job.mapper.UpdateActivityStatusMapper;
import com.yuanfeng.job.service.UpdateActivityStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author Stranger
 * @date 2023/5/16 15:40
 */
@Service
public class UpdateActivityStatusServiceImpl implements UpdateActivityStatusService {

    @Autowired
    private UpdateActivityStatusMapper updateActivityStatusMapper;

    @Autowired
    private OrderServiceClient orderServiceClient;

    @Override
    public Integer updatePromotionGoods() {
        return updateActivityStatusMapper.updatePromotionGoods();
    }

    @Override
    public Integer updatePromotionDiscountBase() {
        return updateActivityStatusMapper.updatePromotionDiscountBase();
    }

    @Override
    public Integer updatePromotionDiscountGoods() {
        return updateActivityStatusMapper.updatePromotionDiscountGoods();
    }

    @Override
    public void updatePromotionDiscountBase2() {
        updateActivityStatusMapper.updatePromotionDiscountBase2();
    }

    @Override
    public void updatePromotionDiscountGoods2() {
        updateActivityStatusMapper.updatePromotionDiscountGoods2();
    }

    @Override
    public void updatePromotionDiscountBase3() {
        updateActivityStatusMapper.updatePromotionDiscountBase3();
    }

    @Override
    public void updatePromotionDiscountGoods3() {
        updateActivityStatusMapper.updatePromotionDiscountGoods3();
    }


    /**
     * 拼团过期状态更新
     * @return
     */
    @Override
    public Integer updatePintuanMarkStatus() {
        // 查询过期的团标识
        List<String> expireMarkIdList = updateActivityStatusMapper.selectExpireMark();
        if (!CollectionUtils.isEmpty(expireMarkIdList)) {
            ExpireMarkIdUpdateDTO udpateParam = new ExpireMarkIdUpdateDTO();
            udpateParam.setExpireMarkIdList(expireMarkIdList);
            // 0,等待成团。1为已成团，2为成团失败，3为已完成退款
            udpateParam.setStatus(2);
            updateActivityStatusMapper.updateMarkStatus(udpateParam);

            // 订单状态更新
            List<String> orderIdList = updateActivityStatusMapper.selectByMarkId(expireMarkIdList);
            udpateParam.setOrderIdList(orderIdList);

            try {

                orderServiceClient.checkGroupBookingStatus(udpateParam);


            } catch (Exception e) {

            }
        }

        Integer count = updateActivityStatusMapper.slectDetailId();
        Integer updatePintuanMarkStatus = 0;
        if (null != count && count.intValue() > 0) {
            updatePintuanMarkStatus = updateActivityStatusMapper.updatePintuanMarkStatus();
        }

        return updatePintuanMarkStatus;
    }

    @Override
    public Integer updatePintuanGoods() {
        return updateActivityStatusMapper.updatePintuanGoods();
    }

    @Override
    public Integer updatePintuanStatus() {
        return updateActivityStatusMapper.updatePintuanStatus();
    }

    @Override
    public Integer updateManjianzengzheGoods() {
        return updateActivityStatusMapper.updateManjianzengzheGoods();
    }

    @Override
    public Integer updateManjianzengzheStatus() {
        return updateActivityStatusMapper.updateManjianzengzheStatus();
    }

    @Override
    public Integer updateSkillGoodsStatus() {
        return updateActivityStatusMapper.updateSkillGoodsStatus();
    }

    @Override
    public Integer updateSkillGoods() {
        return updateActivityStatusMapper.updateSkillGoods();
    }

    @Override
    public Integer updateGoodsStatus() {
        return updateActivityStatusMapper.updateGoodsStatus();
    }

    @Override
    public void updateSkillGoods2() {
        updateActivityStatusMapper.updateSkillGoods2();
    }

    @Override
    public void updateSkillGoodsStatus2() {
        updateActivityStatusMapper.updateSkillGoodsStatus2();
    }

    @Override
    public void updateGoodsStatus2() {
        updateActivityStatusMapper.updateGoodsStatus2();
    }

    @Override
    public Integer updatePintuanStatus2() {
        return updateActivityStatusMapper.updatePintuanStatus2();
    }

    @Override
    public Integer updateManjianzengzheStatus2() {
        return updateActivityStatusMapper.updateManjianzengzheStatus2();
    }

    @Override
    public void updateSkillGoods3() {
        List<ActivityNoneRecSlideDTO> activityGoodsList = updateActivityStatusMapper.queryCommonIdBySeckillStockZero();
        for (ActivityNoneRecSlideDTO slideDTO : activityGoodsList) {
            if(slideDTO.getSeckillNum() > 0){
                updateActivityStatusMapper.updatCommonIsXian(slideDTO.getCommonId(),2);
            }else {
                updateActivityStatusMapper.updatCommonIsXian(slideDTO.getCommonId(),0);
            }
        }

    }
}
